package com.gdut.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gdut.commonutils.R;
import com.gdut.eduservice.entity.EduCourse;
import com.gdut.eduservice.entity.EduTeacher;
import com.gdut.eduservice.service.EduCourseService;
import com.gdut.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Drifiter
 * @create 2021-08-29 9:37
 */
@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexFrontController {



    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;


    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index(){

        //查询前8条热门课程，
        List<EduCourse> eduList  = courseService.selectCourse();
        //查询前8条热门课程，
//        QueryWrapper<EduCourse> courseQueryWrapper = new QueryWrapper<>();
//        courseQueryWrapper.orderByDesc("id");
//        courseQueryWrapper.last("limit 8");
//        List<EduCourse> eduList = courseService.list(courseQueryWrapper);


        // 查询前4条名师
        QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);


        return R.ok().data("eduList",eduList).data("teacherList",teacherList);
    }



}
